package cn.com.xjnt.vas.ordering.domain.entity;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.springframework.format.annotation.DateTimeFormat;

import cn.com.xjnt.vas.manage.domain.entity.Organization;

/**
 * The persistent class for the ordering_food_order database table.
 * 
 */
@Entity
@Table(name = "ordering_food_order")
@NamedQuery(name = "FoodOrder.findAll", query = "SELECT f FROM FoodOrder f")
public class FoodOrder extends com.frameworks.core.entity.IdEntity {
    private static final long serialVersionUID = 1L;

    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date dispatchTime;

    private String orderno;

    @Temporal(TemporalType.TIMESTAMP)
    private Date orderTime;

    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date preFinishTime;

    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date realFinishTime;
    private int num;
    private BigDecimal total;
    private int type;
    private String reason;
    // bi-directional many-to-one association to DiscountInfo
    @OneToMany(mappedBy = "foodOrder")
    private List<DiscountInfo> discountInfos;

    // bi-directional many-to-one association to User
    @ManyToOne
    @JoinColumn(name = "user_id")
    private User user;

    // bi-directional many-to-one association to FoodSeller
    @ManyToOne
    @JoinColumn(name = "menu_id")
    private FoodMenu foodMenu;

    @ManyToOne
    @JoinColumn(name="organization_id")
    private Organization organization;
    
    public FoodOrder() {
    }

    public Date getDispatchTime() {
        return this.dispatchTime;
    }

    public void setDispatchTime(Date dispatchTime) {
        this.dispatchTime = dispatchTime;
    }

    public String getOrderno() {
        return this.orderno;
    }

    public void setOrderno(String orderno) {
        this.orderno = orderno;
    }

    public Date getOrderTime() {
        return this.orderTime;
    }

    public void setOrderTime(Date orderTime) {
        this.orderTime = orderTime;
    }

    public Date getPreFinishTime() {
        return this.preFinishTime;
    }

    public void setPreFinishTime(Date preFinishTime) {
        this.preFinishTime = preFinishTime;
    }

    public Date getRealFinishTime() {
        return this.realFinishTime;
    }

    public void setRealFinishTime(Date realFinishTime) {
        this.realFinishTime = realFinishTime;
    }

    public BigDecimal getTotal() {
        return this.total;
    }

    public void setTotal(BigDecimal total) {
        this.total = total;
    }

    public List<DiscountInfo> getDiscountInfos() {
        return this.discountInfos;
    }

    public void setDiscountInfos(List<DiscountInfo> discountInfos) {
        this.discountInfos = discountInfos;
    }

    public DiscountInfo addDiscountInfo(DiscountInfo discountInfo) {
        getDiscountInfos().add(discountInfo);
        discountInfo.setFoodOrder(this);

        return discountInfo;
    }

    public DiscountInfo removeDiscountInfo(DiscountInfo discountInfo) {
        getDiscountInfos().remove(discountInfo);
        discountInfo.setFoodOrder(null);

        return discountInfo;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public FoodMenu getFoodMenu() {
        return foodMenu;
    }

    public void setFoodMenu(FoodMenu foodMenu) {
        this.foodMenu = foodMenu;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }
    
    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    @PrePersist
    public void onCreate() {
        this.orderTime = new Date();
    }
}